package com.panda.cn.controller;

import cn.hutool.json.JSONObject;
import com.panda.cn.config.aspect.OperLog;
import com.panda.cn.config.aspect.OperLogType;
import com.panda.cn.entity.SysDeptEntity;
import com.panda.cn.service.SysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统部门控制器
 *
 * @author Yanmh
 * @date 2022/09/14
 */
@Slf4j
@RestController
@RequestMapping(value = "/sys/deptcon")
public class SysDeptController {
    
    @Resource
    private SysDeptService sysDeptService;
    
    /**
     * 列表
     *
     * @return {@link List}
     */
    @OperLog(operModul = "部门模块", operType = OperLogType._SEARCH, operDesc = "查询部门树信息")
    @RequestMapping(value = "/tree", method = RequestMethod.POST)
    public List pageList(@RequestBody JSONObject params) {
        return sysDeptService.tree(params);
    }
    
    /**
     * 插入
     *
     * @param params 参数个数
     * @return {@link Long}
     */
    @OperLog(operModul = "部门模块", operType = OperLogType._ADD, operDesc = "添加部门信息")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Long insert(@RequestBody SysDeptEntity params) {
        return sysDeptService.insert(params);
    }
    
    /**
     * 更新
     *
     * @param params 参数个数
     * @return {@link Long}
     */
    @OperLog(operModul = "部门模块", operType = OperLogType._EDIT, operDesc = "修改部门信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Long update(@RequestBody SysDeptEntity params) {
        return sysDeptService.update(params);
    }
    
    /**
     * 逻辑删除
     *
     * @param params 参数个数
     * @return {@link Long}
     */
    @OperLog(operModul = "部门模块", operType = OperLogType._DEL, operDesc = "删除部门信息")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public Long remove(@RequestBody List<Long> params) {
        return sysDeptService.remove(params);
    }
    
}
